﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using LPV_POS.Module;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid;
using LPV_POS.In;
using LPV_POS.mh_pos.mh_doanhthu;
using LPV_POS.mh_pos.mh_khac;
using LPV_POS.Baocao;
using LPV_POS.Baocao.Ellic;
using LPV_POS.Baocao.Bixolon;
using CrystalDecisions.CrystalReports.Engine;
using System.Resources;
using System.Globalization;
using LPV_POS.thuvien_cls;


namespace LPV_POS.mh_pos
{
    public partial class mh_thuchi : DevExpress.XtraEditors.XtraForm
    {
        //Boolean bInComPort = false;\
        thongbao_lang thongbao;
        CultureInfo culture;
        string str_lang = "";
        cpublic ocpublic;
        int i1;
        int i2;
        int i3;
        string Print_Align_Left = ((char)(27)).ToString() + ((char)(97)).ToString() + '\0';
        mh_tungaydenngay frm_tungaydenngay;
        xulyngaythangnam ngaythang;
        thuvien tv;
        DataTable tb;
        string[] s;
        object[] o;
        string m_makhachhang = "";

        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang6_PhuThu).Assembly);
                this.pag_thu.Text = rm.GetString("thu", culture);
                this.page_chi.Text = rm.GetString("chi", culture);
                label2.Text = rm.GetString("lydothu", culture);
                bton_lydo.Text = rm.GetString("lydo", culture);
                this.col_lydothu.Caption = rm.GetString("lydothu", culture);
                check_MAKHACHHANG.Text = rm.GetString("khachhang", culture);
                bton_chonkh.Text = rm.GetString("chon", culture);
                label1.Text = rm.GetString("thanhtien", culture);
                bton_xoa.Text = rm.GetString("xoa", culture);
                bton_congnobandau.Text = rm.GetString("congnobandau", culture);
                bton_xemtatca_thu.Text = rm.GetString("xemtatca", culture);
                bton_timthu.Text = rm.GetString("tim", culture);
                bton_hienhanhphieuthu.Text = rm.GetString("inphieuhienhanh", culture);
                bton_intatcaphieuthu.Text = rm.GetString("intatca", culture);
                bton_suaphieuthu.Text = rm.GetString("sua", culture);
                bton_xoaphieuthu.Text = rm.GetString("xoa", culture);
                bton_luuphieuthu.Text = rm.GetString("luu", culture);
                bton_thoat.Text = rm.GetString("thoat", culture);
                this.col_tenlydothu.Caption = rm.GetString("lydothu", culture);
                this.col_ngay.Caption = rm.GetString("ngay", culture);
                this.col_sotien.Caption = rm.GetString("thanhtien", culture);
                this.grvPhieuThu.GroupPanelText = rm.GetString("danhsachphieuthu", culture);
                bton_them.Text = rm.GetString("them", culture);
                bton_sualydothu.Text = rm.GetString("sua", culture);
                bton_xoalydothu.Text = rm.GetString("xoa", culture);
                bton_luulydothu.Text = rm.GetString("luu", culture);

                label4.Text = rm.GetString("lydochi", culture);
                col_lydochi.Caption = rm.GetString("lydochi", culture);
                bton_lydochi.Text = rm.GetString("lydo", culture);
                //label5.Text = rm.GetString("khachhang", culture);
                label6.Text = rm.GetString("thanhtien", culture);
                bton_xoachi.Text = rm.GetString("xoa", culture);
                bton_xemtatca_chi.Text = rm.GetString("xemtatca", culture);
                bton_timchi.Text = rm.GetString("tim", culture);
                bton_hienhanhphieuchi.Text = rm.GetString("inphieuhienhanh", culture);
                bton_intatcaphieuchi.Text = rm.GetString("intatca", culture);
                this.grvPhieuChi.GroupPanelText = rm.GetString("danhsachphieuchi", culture);
                this.col_tenlydochi.Caption = rm.GetString("lydochi", culture);
                this.col_ngaychi.Caption = rm.GetString("ngay", culture);
                this.col_sotienchi.Caption = rm.GetString("thanhtien", culture);

                bton_suaphieuchi.Text = rm.GetString("sua", culture);
                bton_xoaphieuchi.Text = rm.GetString("xoa", culture);
                bton_luuphieuchi.Text = rm.GetString("luu", culture);
                bton_thoatchi.Text = rm.GetString("thoat", culture);
                bton_chonNCC.Text = rm.GetString("chon", culture);
                //page_chi.Text = rm.GetString("chi", cul ture);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion

        #region cac ham va phuong thuc
        string f_splitString4Column(string a, string b, string c, string d, int i1, int i2, int i3)
        {//i1: 32; i2:7; i3: 17
            string str = "";
            str = a;
            str += new cpublic().Spacestring(i1 - a.Length - b.Length);
            str += b;
            str += new cpublic().Spacestring(i2 - c.Length);
            str += c;
            str += new cpublic().Spacestring(i3 - d.Length);
            str += d;
            return str;
        }
        // hiển thị du lieu len luoi ly do thu
        private DataTable f_luoilydothu()
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose" };
            o = new object[] { 1, 1 };
            tb = tv.SP_SelectDataTable("sp_mh_thuchi", s, o);
            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "OBJID DESC";
            return dv_temp.ToTable();
        }
        // hien thi du lieu len luoi ly do chi
        private DataTable f_luoilydochi()
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose" };
            o = new object[] { 1, 3};
            tb = tv.SP_SelectDataTable("sp_mh_thuchi", s, o);
            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "OBJID DESC";
            return dv_temp.ToTable();
        }

        // hien thi du lieu phieu thu theo thoi gian
        private DataTable f_luoilydothutheothoigian(string tungay, string denngay)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@TUNGAY", "@DENNGAY" };
            o = new object[] { 1, 5,tungay,denngay };
            tb = tv.SP_SelectDataTable("sp_mh_thuchi", s, o);
            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "DOCID DESC";
            return dv_temp.ToTable();
        }

        // hien thi du lieu phieu chi theo thoi gian
        private DataTable f_luoilydochitheothoigian(string tungay, string denngay)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@TUNGAY", "@DENNGAY" };
            o = new object[] { 1, 6, tungay, denngay };
            tb = tv.SP_SelectDataTable("sp_mh_thuchi", s, o);
            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "DOCID DESC";
            return dv_temp.ToTable();
        }

        // chinh su ly do thu
        private int f_updatelydothu(string malydothu, string tenlydothu)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@OBJID", "@OBJNAME" };
            o = new object[] { 2, 1, malydothu, tenlydothu };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }
        // chinh sua ly do chi
        private int f_updatelydochi(string malydochi, string tenlydochi)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@OBJID", "@OBJNAME" };
            o = new object[] { 2, 3, malydochi, tenlydochi };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }

        // chinh sua phieu thu
        private int f_updatephieuthu(string maphieuthu, string tongtien, string makhachhang)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@DOCID", "@TONGTIEN", "@MAKHACHHANG" };
            o = new object[] { 2, 2, maphieuthu, tongtien, makhachhang };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }
      
            // chinh sua phieu chi
        private int f_updatephieuchi(string maphieuchi, string tongtien)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@DOCID", "@TONGTIEN", "@MANCC", "@iCONGNO_NCC" };
            o = new object[] { 2, 4, maphieuchi, tongtien, txt_maNCC.Text.Trim(), new cpublic().Registry_Get("chkCONGNO_NHACUNGCAP") + "" == "True" };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }

        // insert ly do thu
        private int f_insertlydothu(string lydothu)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@OBJNAME" };
            o = new object[] { 3, 1, lydothu };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }

        // insert ly do chi
        private int f_insertlydochi(string lydochi)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@OBJNAME" };
            o = new object[] { 3, 3, lydochi };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }

        // delete ly do thu
        private int f_deletelydothu(string malydothu)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@OBJID" };
            o = new object[] { 4, 1, malydothu };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }
        // delete ly do chi
          private int f_deletelydochi(string malydochi)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@OBJID" };
            o = new object[] { 4, 3, malydochi};
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }

        // delete phieu thu
        private int f_deletephieuthu(string maphieuthu)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@DOCID" };
            o = new object[] { 4, 2, maphieuthu };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }

        // delete phieu chi
        private int f_deletephieuchi(string maphieuchi)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@DOCID", "@iCONGNO_NCC" };
            o = new object[] { 4, 4, maphieuchi, new cpublic().Registry_Get("chkCONGNO_NHACUNGCAP") + "" == "True" };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }

        // Select danh sach phieu thu
        private DataTable f_selectdsphieuthu(int choose)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose" };
            o = new object[] { 1, choose };
            tb = tv.SP_SelectDataTable("sp_mh_thuchi", s, o);
             tb.Columns.Add("STT", typeof(int));
            for (int i = 0; i < tb.Rows.Count; i++)
                tb.Rows[i]["STT"] = i + 1;

            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "STT DESC";
            return dv_temp.ToTable();
        }

        // select danh sach phieu chi
        private DataTable f_selectdsphieuchi(int flag)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose" };
            o = new object[] { 1, flag };
            tb = tv.SP_SelectDataTable("sp_mh_thuchi", s, o);
             tb.Columns.Add("STT", typeof(int));
            for (int i = 0; i < tb.Rows.Count; i++)
                tb.Rows[i]["STT"] = i + 1;

            DataView dv_temp = tb.DefaultView;
            dv_temp.Sort = "STT DESC";
            return dv_temp.ToTable();
        }

        // them mot phieu thu
        private int f_insertphieuthu(string malydothu, string tongtien, string makhachhang)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@MALYDOTHU", "@TONGTIEN", "@MAKHACHHANG" };
            o = new object[] { 3, 2, malydothu, tongtien, makhachhang };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }
        // them mot phieu chi
        private int f_insertphieuchi(string malydochi, string tongtien)
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@choose", "@MALYDOCHI", "@TONGTIEN", "@MANCC", "@iCONGNO_NCC" };
            o = new object[] { 3, 4, malydochi, tongtien, txt_maNCC.Text.Trim(), new cpublic().Registry_Get("chkCONGNO_NHACUNGCAP") + "" == "True" };
            int ketqua = tv.SP_Update("sp_mh_thuchi", s, o);
            return ketqua;
        }
        // ngay thang hien hanh
        private string f_chuoingayhienhanh()
        {
            string ngaythangnam = "";
            ngaythang = new xulyngaythangnam();
            tv = new thuvien();
            s = new string[] { "@flag", "@CHOOSE" };
            o = new object[] { 1, 1 };
            tb = tv.SP_SelectDataTable("sp_mhcompany", s, o);
            if (tb.Rows.Count > 0)
                ngaythangnam = ngaythang.chuoingay(tb.Rows[0]["NGAYHIENHANH"] + "");
            return ngaythangnam;
        }
        // select thong tin cong ty
        private DataTable f_selectgetinfo_company()
        {
            tv = new thuvien();
            s = new string[] { "@flag", "@CHOOSE" };
            o = new object[] { 1, 1 };
            tb = tv.SP_SelectDataTable("sp_mhcompany", s, o);
            return tb;
        }
        private int f_inphieuthu_chihienhanh( string loaibaocao,string lydothu, string ngay, string sotien, Boolean iPhieuThu)
        {
            ocpublic = new cpublic();
            i1 = 32;
            i2 = 14;
            i3 = 10;
            string tencongty = "";
            string dienthoai = "";
            string diachi = "";
           

            Mod_header_report header_report = new Mod_header_report();

            tb = header_report.f_selectheaderreport();
            if (tb.Rows.Count > 0)
            {
                tencongty = tb.Rows[0]["HEADER"] + "";
                dienthoai = tb.Rows[0]["PHONE"] + "";
                diachi = tb.Rows[0]["ADDRESS"] + "";
            }
            //print_usb BIEN_NHAN
            thuvien tv = new thuvien();
            DataTable tbBN = tv.SP_SelectDataTable("sp_DM_MAYIN_BIENNHAN", null, null);
            DataView dv = tbBN.DefaultView;
            dv.Sort = "COMNAME";
            int vitri = dv.Find(new object[] { "USB" });
            int vitri_bixolon = dv.Find(new object[] { "BIXOLON" });
            int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
            if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
            {
                #region "In bill tieng viet"
                if (iPhieuThu)
                {
                    ReportDocument rpt;
                    if(vitri > -1)
                        rpt = new bc_BaoCaoThuChi_Thu_TatCa();
                    else
                        rpt = new bc_BaoCaoThuChi_Thu_TatCa_Bixolon();

                    rpt.DataDefinition.FormulaFields["tencongty"].Text = "'" + tencongty.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["dienthoai"].Text = "'" + dienthoai.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["diachi"].Text = "'" + diachi.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["ngayin"].Text = "'" + "In báo cáo ngày " + DateTime.Today.ToString("dd/MM/yyyy") + "'";
                    ///
                    DataTable tbBaoCaoThuChi_Thu_TatCa = ((DataTable)grdPhieuThu.DataSource).Clone();
                    tbBaoCaoThuChi_Thu_TatCa.TableName = "BaoCaoThuChi_Thu_TatCa";
                    //tbBaoCaoThuChi_Thu_TatCa.WriteXmlSchema(@"D:\Project\LPV-POS\LPV-POS\Baocao\ds_BaoCaoThuChi_Thu_TatCa.xsd");
                    DataRow drBaoCaoThuChi_Thu_TatCa = tbBaoCaoThuChi_Thu_TatCa.NewRow();
                    DataRow drSelectTion = grvPhieuThu.GetDataRow(grvPhieuThu.FocusedRowHandle);
                    if (drSelectTion != null)
                        drBaoCaoThuChi_Thu_TatCa.ItemArray = drSelectTion.ItemArray;
                    tbBaoCaoThuChi_Thu_TatCa.Rows.Add(drBaoCaoThuChi_Thu_TatCa);
                    rpt.SetDataSource(tbBaoCaoThuChi_Thu_TatCa);
                    #region "   PrinterDefault"
                    System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                    string sPrinterDefault = cls.PrinterName;
                    rpt.PrintOptions.PrinterName = sPrinterDefault;
                    #endregion
                    try
                    {
                        if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                        {
                            mh_View frm = new mh_View(rpt);
                            frm.Show();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    rpt.PrintToPrinter(0, true, 1, 100);

                }
                else
                {//PHIEU CHI
                    bc_BaoCaoThuChi_Chi_TatCa rpt = new bc_BaoCaoThuChi_Chi_TatCa();
                    rpt.DataDefinition.FormulaFields["tencongty"].Text = "'" + tencongty.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["dienthoai"].Text = "'" + dienthoai.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["diachi"].Text = "'" + diachi.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["ngayin"].Text = "'" + "In báo cáo ngày " + DateTime.Today.ToString("dd/MM/yyyy") + "'";
                    ///
                    DataTable tbBaoCaoThuChi_Chi_TatCa = ((DataTable)grdPhieuChi.DataSource).Clone();
                    tbBaoCaoThuChi_Chi_TatCa.TableName = "BaoCaoThuChi_Chi_TatCa";
                    //tbBaoCaoThuChi_Chi_TatCa.WriteXmlSchema(@"D:\Project\LPV-POS\LPV-POS\Baocao\ds_BaoCaoThuChi_Chi_TatCa.xsd");
                    DataRow drBaoCaoThuChi_Chi_TatCa = tbBaoCaoThuChi_Chi_TatCa.NewRow();
                    DataRow drSelectTion = grvPhieuChi.GetDataRow(grvPhieuChi.FocusedRowHandle);
                    if (drSelectTion != null)
                        drBaoCaoThuChi_Chi_TatCa.ItemArray = drSelectTion.ItemArray;
                    tbBaoCaoThuChi_Chi_TatCa.Rows.Add(drBaoCaoThuChi_Chi_TatCa);
                    rpt.SetDataSource(tbBaoCaoThuChi_Chi_TatCa);
                    #region "   PrinterDefault"
                    System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                    string sPrinterDefault = cls.PrinterName;
                    rpt.PrintOptions.PrinterName = sPrinterDefault;
                    #endregion
                    try
                    {
                        if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                        {
                            mh_View frm = new mh_View(rpt);
                            frm.Show();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    rpt.PrintToPrinter(0, true, 1, 100);
                }
               
                #endregion
                
            }
            else
            {
                //.	Khởi tạo Class: 
                PrintCOMs oPrintCOM = new PrintCOMs(PrintCOMs.Print_Type.Print_BILL);
                //	Start máy in: 
                SerialPort_LPV[] oSerialPort_LPVs = oPrintCOM.Print_Start();

                foreach (SerialPort_LPV oSerialPort_LPV in oSerialPort_LPVs)
                {


                    if (oSerialPort_LPV != null)
                    {
                        oSerialPort_LPV.Write(Print_Align_Left);
                        if (iPhieuThu == true)
                            oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "PHIEU THU", "", "", "");
                        else
                            oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "PHIEU CHI", "", "", "");

                        oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                        if (tencongty != "")
                            oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                        if (dienthoai != "")
                            oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                        if (diachi != "")
                            oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                        oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);

                        oSerialPort_LPV.WriteLine(this.f_splitString4Column("Ly do", "", "Ngay   ", "So tien", i1, i2, i3));
                        lydothu = ocpublic.RemoveSign4VietnameseString(lydothu);
                        oSerialPort_LPV.WriteLine(this.f_splitString4Column(lydothu, "", ngay, sotien, i1, i2, i3));


                        oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                        oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao " + f_chuoingayhienhanh(), "", "", "");
                        oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        oPrintCOM.Print_Bottom(oSerialPort_LPV);//
                        oPrintCOM.Print_Close();
                    }
                }
            }
            return 1;
        }
        
        // in toan bo phieu thu 
        private int f_intatcaphieuthu()
        {
            ocpublic = new cpublic();
            i1 = 32;
            i2 = 14;
            i3 = 10;
            string tencongty = "";
            string dienthoai = "";
            string diachi = "";
           
            Mod_header_report header_report = new Mod_header_report();


            tb = header_report.f_selectheaderreport();
            if (tb.Rows.Count > 0)
            {
                tencongty = tb.Rows[0]["HEADER"] + "";
                dienthoai = tb.Rows[0]["PHONE"] + "";
                diachi = tb.Rows[0]["ADDRESS"] + "";
            }
            //print_usb BIEN_NHAN
            thuvien tv = new thuvien();
            DataTable tbBN = tv.SP_SelectDataTable("sp_DM_MAYIN_BIENNHAN", null, null);
            DataView dv = tbBN.DefaultView;
            dv.Sort = "COMNAME";
            int vitri = dv.Find(new object[] { "USB" });
            int vitri_bixolon = dv.Find(new object[] { "BIXOLON" });
            int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
            if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
            //if (!bInComPort)
            {
                #region "in bill tieng viet"
                ReportDocument rpt; 
                if(vitri > -1)
                    rpt = new bc_BaoCaoThuChi_Thu_TatCa();
                else
                    rpt = new bc_BaoCaoThuChi_Thu_TatCa_Bixolon();

                rpt.DataDefinition.FormulaFields["tencongty"].Text = "'" + tencongty.Trim() + "'";
                rpt.DataDefinition.FormulaFields["dienthoai"].Text = "'" + dienthoai.Trim() + "'";
                rpt.DataDefinition.FormulaFields["diachi"].Text = "'" + diachi.Trim() + "'";
                rpt.DataDefinition.FormulaFields["ngayin"].Text = "'" + "In báo cáo ngày " + DateTime.Today.ToString("dd/MM/yyyy") + "'";
                ///
                DataTable tbBaoCaoThuChi_Thu_TatCa = ((DataTable)grdPhieuThu.DataSource);
                tbBaoCaoThuChi_Thu_TatCa.TableName = "BaoCaoThuChi_Thu_TatCa";
                //tbBaoCaoThuChi_Thu_TatCa.WriteXmlSchema(@"D:\Project\LPV-POS\LPV-POS\Baocao\ds_BaoCaoThuChi_Thu_TatCa.xsd");
                rpt.SetDataSource(tbBaoCaoThuChi_Thu_TatCa);
                #region "   PrinterDefault"
                System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                string sPrinterDefault = cls.PrinterName;
                rpt.PrintOptions.PrinterName = sPrinterDefault;
                #endregion
                try
                {
                    if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                    {
                        mh_View frm = new mh_View(rpt);
                        frm.Show();
                    }
                }
                catch (Exception ex)
                {
                }
                rpt.PrintToPrinter(0, true, 1, 100);
                #endregion
                
            }
            else
            {
                //.	Khởi tạo Class: 
                PrintCOMs oPrintCOM = new PrintCOMs(PrintCOMs.Print_Type.Print_BILL);
                //	Start máy in: 
                SerialPort_LPV[] oSerialPort_LPVs = oPrintCOM.Print_Start();

                foreach (SerialPort_LPV oSerialPort_LPV in oSerialPort_LPVs)
                {

                    if (oSerialPort_LPV != null)
                    {
                        oSerialPort_LPV.Write(Print_Align_Left);
                        oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "PHIEU THU", "", "", "");
                        oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        if (tencongty != "")
                            oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");

                        if (dienthoai != "")
                            oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");

                        if (diachi != "")
                            oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                        oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                        oSerialPort_LPV.WriteLine(this.f_splitString4Column("Ly do thu", "", "Ngay    ", "So tien", i1, i2, i3));
                        //oPrintCOM.Print_Content(PrintCOM.aligns.Align_Left, PrintCOM.Fonts.Font_Normal, "Lý do thu", "Ngày   ", "Số tiền", "");

                        string lydothu = "";
                        string ngay = "";
                        string sotien = "";
                        for (int i = 0; i < grvPhieuThu.RowCount; i++)
                        {
                            lydothu = ocpublic.RemoveSign4VietnameseString(grvPhieuThu.GetRowCellDisplayText(i, col_tenlydothu) + "");
                            ngay = grvPhieuThu.GetRowCellDisplayText(i, col_ngay) + "   ";
                            sotien = decimal.Parse(grvPhieuThu.GetRowCellDisplayText(i, col_sotien) + "").ToString("N0");
                            oSerialPort_LPV.WriteLine(this.f_splitString4Column(lydothu, "", ngay, sotien, i1, i2, i3));
                            //   oPrintCOM.Print_Content(PrintCOM.aligns.Align_Left, PrintCOM.Fonts.Font_Normal, lydothu,  ngay, sotien,"");
                        }

                        oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                        oSerialPort_LPV.WriteLine(this.f_splitString4Column("In bao cao " + ocpublic.RemoveSign4VietnameseString(f_chuoingayhienhanh().ToLower()), "", "", "", i1, i2, i3));
                        oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                        oPrintCOM.Print_Bottom(oSerialPort_LPV);//
                        oPrintCOM.Print_Close();
                    }
                }
            }
            return 1;

        }

        // in toan bo phieu chi 
        private int f_intatcaphieuchi()
        {//
            try
            {

                ocpublic = new cpublic();
                i1 = 32;
                i2 = 14;
                i3 = 10;
                string tencongty = "";
                string dienthoai = "";
                string diachi = "";

                Mod_header_report header_report = new Mod_header_report();

                tb = header_report.f_selectheaderreport();
                if (tb.Rows.Count > 0)
                {
                    tencongty = tb.Rows[0]["HEADER"] + "";
                    dienthoai = tb.Rows[0]["PHONE"] + "";
                    diachi = tb.Rows[0]["ADDRESS"] + "";
                }
                //print_usb BIEN_NHAN
                thuvien tv = new thuvien();
                DataTable tbBN = tv.SP_SelectDataTable("sp_DM_MAYIN_BIENNHAN", null, null);
                DataView dv = tbBN.DefaultView;
                dv.Sort = "COMNAME";
                int vitri = dv.Find(new object[] { "USB" });
                int vitri_bixolon = dv.Find(new object[] { "BIXOLON" });
                int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                //if (!bInComPort)
                {
                    #region "in bill tieng viet"
                    ReportDocument rpt; 
                    if(vitri > -1)
                        rpt = new bc_BaoCaoThuChi_Chi_TatCa();
                    else
                        rpt = new bc_BaoCaoThuChi_Chi_TatCa_Bixolon();

                    rpt.DataDefinition.FormulaFields["tencongty"].Text = "'" + tencongty.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["dienthoai"].Text = "'" + dienthoai.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["diachi"].Text = "'" + diachi.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["ngayin"].Text = "'" + "In báo cáo ngày " + DateTime.Today.ToString("dd/MM/yyyy") + "'";
                    ///
                    DataTable tbBaoCaoThuChi_Chi_TatCa = ((DataTable)grdPhieuChi.DataSource);
                    tbBaoCaoThuChi_Chi_TatCa.TableName = "BaoCaoThuChi_Chi_TatCa";
                    //tbBaoCaoThuChi_Chi_TatCa.WriteXmlSchema(@"D:\Project\LPV-POS\LPV-POS\Baocao\ds_BaoCaoThuChi_Chi_TatCa.xsd");

                    rpt.SetDataSource(tbBaoCaoThuChi_Chi_TatCa);
                    #region "   PrinterDefault"
                    System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                    string sPrinterDefault = cls.PrinterName;
                    rpt.PrintOptions.PrinterName = sPrinterDefault;
                    #endregion
                    try
                    {
                        if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                        {
                            mh_View frm = new mh_View(rpt);
                            frm.Show();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    rpt.PrintToPrinter(0, true, 1, 100);
                    #endregion
                    
                }
                else
                {
                    //.	Khởi tạo Class: 
                    PrintCOMs oPrintCOM = new PrintCOMs(PrintCOMs.Print_Type.Print_BILL);
                    //	Start máy in: 
                    SerialPort_LPV[] oSerialPort_LPVs = oPrintCOM.Print_Start();

                    foreach (SerialPort_LPV oSerialPort_LPV in oSerialPort_LPVs)
                    {

                        if (oSerialPort_LPV != null)
                        {
                            oSerialPort_LPV.Write(Print_Align_Left);
                            oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "PHIEU CHI", "", "", "");

                            oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                            if (tencongty != "")
                                oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");

                            if (dienthoai != "")
                                oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");

                            if (diachi != "")
                                oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                            oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                            oSerialPort_LPV.WriteLine(this.f_splitString4Column("Ly do chi", "", "Ngay    ", "So tien", i1, i2, i3));
                            //oPrintCOM.Print_Content(PrintCOM.aligns.Align_Left, PrintCOM.Fonts.Font_Normal, "Lý do thu", "Ngày   ", "Số tiền", "");

                            string lydochi = "";
                            string ngay = "";
                            string sotien = "";
                            for (int i = 0; i < grvPhieuChi.RowCount; i++)
                            {
                                lydochi = ocpublic.RemoveSign4VietnameseString(grvPhieuChi.GetRowCellDisplayText(i, col_lydochi) + "");
                                ngay = grvPhieuChi.GetRowCellDisplayText(i, col_ngaychi) + "   ";
                                sotien = decimal.Parse(grvPhieuChi.GetRowCellDisplayText(i, col_sotienchi) + "").ToString("N0");
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column(lydochi, "", ngay, sotien, i1, i2, i3));
                            }

                            oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                            oSerialPort_LPV.WriteLine(this.f_splitString4Column("In bao cao " + ocpublic.RemoveSign4VietnameseString(f_chuoingayhienhanh().ToLower()), "", "", "", i1, i2, i3));
                            oPrintCOM.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                            oPrintCOM.Print_Bottom(oSerialPort_LPV);//
                            oPrintCOM.Print_Close();

                        }
                    }
                }
            }
            catch (Exception)
            {

                return 0;
            }
            return 1;
        }

        #endregion

        #region cac su kien
        public mh_thuchi()
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
        }

        private void mh_thuchi_Load(object sender, EventArgs e)
        {

            cpublic ocpublic = new cpublic();
            str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);

            // hien thi ly do thu
            luoi_lydothu.MainView = grid_lydothu;
            luoi_lydothu.DataSource = null;
            luoi_lydothu.DataSource = f_luoilydothu();

            // hien thi ds phieu thu
            grdPhieuThu.MainView = grvPhieuThu;
            grdPhieuThu.DataSource = null;
            grdPhieuThu.DataSource = f_selectdsphieuthu(7);

            // hien thi ly do chi
            luoi_lydochi.MainView = grid_lydochi;
            luoi_lydochi.DataSource = null;
            luoi_lydochi.DataSource = f_luoilydochi();

            // hien thi ds phieu chi
            grdPhieuChi.MainView = grvPhieuChi;            
            grdPhieuChi.DataSource = f_selectdsphieuchi(8);


            txt_lydothu.Enabled = false;
            bton_lydo.Enabled = false;
            bton_luulydothu.Enabled = false;

            txt_lydochi.Enabled = false;
            bton_lydochi.Enabled = false;
            bton_luulydochi.Enabled = false;

            this.CancelButton = bton_thoat;

        }

        private void bton_them_Click(object sender, EventArgs e)
        {
            txt_lydothu.Enabled = true;
            txt_lydothu.Text = "";
            bton_lydo.Enabled = true;
            bton_luulydothu.Enabled = true;
            Variable.str_trangthaithemsua = "them";

        }

        private void bton_themlydochi_Click(object sender, EventArgs e)
        {
            txt_lydochi.Enabled = true;
            txt_lydochi.Text = "";
            bton_lydochi.Enabled = true;
            bton_luulydochi.Enabled = true;
            Variable.str_trangthaithemsuachi = "them";
        }


        private void bton_lydo_Click(object sender, EventArgs e)
        {
            //mh_chu frm_chu = new mh_chu();
            //frm_chu.ControlBox = false;
            //Variable.int_vitri = 0;
            //Variable.int_vitri = Convert.ToInt32(bton_lydo.Tag);
            //frm_chu.ShowDialog();

            //if (Variable.str_chu == "")
            //    return;
            //txt_lydothu.Text = Variable.str_chu;
            txt_lydothu.Text = new cpublic().loadformchu_point(350,250);
        }
        private void bton_thoat_Click(object sender, EventArgs e)
        {
            Mod_messagebox mess = new Mod_messagebox();
           // mess.messagebox_pos("Thông báo", "Bạn muốn thoát?", loaithongbao.yesno.GetHashCode());
            thongbao = new thongbao_lang();
            thongbao.show_info(str_lang, "chatchan_thoat");
            if (Variable.thongbao == true)
            {
                this.Close();
            }
        }

        private void bton_thoatchi_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            thongbao.show_info(str_lang, "chatchan_thoat");
            if (Variable.thongbao == true)
            {
                this.Close();
            }
        }
        private void grid_lydothu_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (luoi_lydothu.DefaultView.RowCount > 0)
            {
                GridView grid = (GridView)sender;

                int chiso = e.FocusedRowHandle;
                string _chiso = Convert.ToString(chiso);
                GridColumn col = grid_lydothu.FocusedColumn;
                txt_lydothu.Text = grid_lydothu.GetRowCellDisplayText(chiso, col_lydothu) + "";
                txt_sotien.Text = "";

                txt_lydothu.Enabled = false;
                bton_lydo.Enabled = false;
                bton_luulydothu.Enabled = false;
            }

        }
        private void grid_lydochi_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            if (luoi_lydochi.DefaultView.RowCount > 0)
            {
                GridView grid = (GridView)sender;

                int chiso = e.FocusedRowHandle;
                string _chiso = Convert.ToString(chiso);
                GridColumn col = grid_lydochi.FocusedColumn;
                txt_lydochi.Text = grid_lydochi.GetRowCellDisplayText(chiso, col_tenlydochi) + "";
                txt_sotienchi.Text = "";

                txt_lydochi.Enabled = false;
                bton_lydochi.Enabled = false;
                bton_luulydochi.Enabled = false;
            }
        }

        private void bton_luulydothu_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            int ketqua;
            if (txt_lydothu.Text == "")       // không thể luu neu chua nhap ten ly do thu
                return;
            int chiso = grid_lydothu.FocusedRowHandle;
            if (Variable.str_trangthaithemsua == "them")
            {
                ketqua = f_insertlydothu(txt_lydothu.Text);

                if (ketqua == -1)
                {
                    //thongbao = new thongbao_lang();
                    thongbao.show_info(str_lang, "khongthanhcong");
                    Mod_messagebox mess = new Mod_messagebox();
                    //mess.messagebox_pos("Thông báo", "Thêm không thành công", loaithongbao.canhbao.GetHashCode());
                    return;
                }
            }
            else if (Variable.str_trangthaithemsua == "sua")
            {
                string malydothu = grid_lydothu.GetRowCellValue(grid_lydothu.FocusedRowHandle, col_malydothu).ToString();
                ketqua = f_updatelydothu(malydothu, txt_lydothu.Text);

                if (ketqua == -1)
                {
                    //Mod_messagebox mess = new Mod_messagebox();
                    //mess.messagebox_pos("Thông báo", "Chỉnh sửa không thành công", loaithongbao.canhbao.GetHashCode());
                    thongbao.show_info(str_lang, "khongthanhcong");
                    return;
                }
                grdPhieuThu.DataSource = f_selectdsphieuthu(2);
            }
            luoi_lydothu.DataSource = null;
            luoi_lydothu.DataSource = f_luoilydothu();
            if (Variable.str_trangthaithemsua == "sua")
                grid_lydothu.FocusedRowHandle = chiso;
        }

       //----------------------------------------------------------------------------------------------------------------------------

        private void bton_luulydochi_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            int ketqua;

            if (txt_lydochi.Text == "")       // không thể luu neu chua nhap ten ly do chi
                return;
            int chiso = grid_lydochi.FocusedRowHandle;
            if (Variable.str_trangthaithemsuachi == "them")
            {
                ketqua = f_insertlydochi(txt_lydochi.Text);

                if (ketqua == 2)
                {
                    thongbao.show_info(str_lang, "khongthanhcong");
                    //Mod_messagebox mess = new Mod_messagebox();
                    //mess.messagebox_pos("Thông báo", "Thêm không thành công", loaithongbao.canhbao.GetHashCode());
                    return;
                }
            }
            else if (Variable.str_trangthaithemsuachi == "sua")
            {
                string malydochi = grid_lydochi.GetRowCellValue(grid_lydochi.FocusedRowHandle, col_malydochi).ToString();
                ketqua = f_updatelydochi(malydochi, txt_lydochi.Text);

                if (ketqua == 2)
                {
                    thongbao.show_info(str_lang, "khongthanhcong");
                    //Mod_messagebox mess = new Mod_messagebox();
                    //mess.messagebox_pos("Thông báo", "Chỉnh sửa không thành công", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                grdPhieuChi.DataSource = f_selectdsphieuchi(4);
            }
            luoi_lydochi.DataSource = null;
            luoi_lydochi.DataSource = f_luoilydochi();
            if (Variable.str_trangthaithemsuachi == "sua")
                grid_lydochi.FocusedRowHandle = chiso;
        }

        private void bton_sualydothu_Click(object sender, EventArgs e)
        {
            txt_lydothu.Enabled = true;
            bton_lydo.Enabled = true;
            bton_luulydothu.Enabled = true;
            Variable.str_trangthaithemsua = "sua";
        }
        private void bton_sualydochi_Click(object sender, EventArgs e)
        {
            txt_lydochi.Enabled = true;
            bton_lydochi.Enabled = true;
            bton_luulydochi.Enabled = true;
            Variable.str_trangthaithemsuachi = "sua";
        }


        private void bton_xoalydothu_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            int ketqua;
            if (luoi_lydothu.DefaultView.RowCount <= 0)    // neu khong co dong nao thi khong xoa duoc
                return;
            string malydothu = grid_lydothu.GetRowCellValue(grid_lydothu.FocusedRowHandle, col_malydothu).ToString();
            thongbao.show_info(str_lang, "chatchan");
            //Mod_messagebox mess = new Mod_messagebox();
            //mess.messagebox_pos("Thông báo", "Bạn muốn xóa?", loaithongbao.yesno.GetHashCode());
            if (Variable.thongbao == true)
            {
                ketqua = f_deletelydothu(malydothu);
                if (ketqua == 2)
                {
                    thongbao.show_info(str_lang, "khongthanhcong");
                    //Mod_messagebox mess = new Mod_messagebox();
                    //mess.messagebox_pos("Thông báo", "Xóa không thành công", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                // xoa mot dong trong luoi ly do thu
                int chiso;
                chiso = ((ColumnView)luoi_lydothu.Views[0]).FocusedRowHandle;
                DataView tam = (DataView)luoi_lydothu.Views[0].DataSource;
                tam.Delete(chiso);

            }

        }

        private void bton_xoalydochi_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            int ketqua;
            if (luoi_lydochi.DefaultView.RowCount <= 0)    // neu khong co dong nao thi khong xoa duoc
                return;
            string malydochi = grid_lydochi.GetRowCellValue(grid_lydochi.FocusedRowHandle, col_malydochi).ToString();
            thongbao.show_info(str_lang, "chatchan");
            //Mod_messagebox mess = new Mod_messagebox();
            //mess.messagebox_pos("Thông báo", "Bạn muốn xóa?", loaithongbao.yesno.GetHashCode());
            if (Variable.thongbao == true)
            {
                ketqua = f_deletelydochi(malydochi);
                if (ketqua == 2)
                {
                    thongbao.show_info(str_lang, "khongthanhcong");
                    //Mod_messagebox mess = new Mod_messagebox();
                   // mess.messagebox_pos("Thông báo", "Xóa không thành công", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                // xoa mot dong trong luoi ly do thu
                int chiso;
                chiso = ((ColumnView)luoi_lydochi.Views[0]).FocusedRowHandle;
                DataView tam = (DataView)luoi_lydochi.Views[0].DataSource;
                tam.Delete(chiso);
            }
        }

        private void bton_1_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();
            txt_sotien.Text += bton_1.Text;

        }
        private void bton_2_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();
            txt_sotien.Text += bton_2.Text;

        }
        private void bton_3_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();
            txt_sotien.Text += bton_3.Text;

        }

        private void bton_4_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();
            txt_sotien.Text += bton_4.Text;

        }

        private void bton_5_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();
            txt_sotien.Text += bton_5.Text;

        }

        private void bton_6_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();

            txt_sotien.Text += bton_6.Text;
             
        }

        private void bton_7_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();

            txt_sotien.Text += bton_7.Text;
        }

        private void bton_8_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();
            txt_sotien.Text += bton_8.Text;

        }

        private void bton_9_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();
            txt_sotien.Text += bton_9.Text;
            
        }
        private void bton_0_Click(object sender, EventArgs e)
        {
            txt_sotien.Focus();
            txt_sotien.Text += bton_0.Text;
            
        }

        private void bton_xoachon_Click(object sender, EventArgs e)
        {
            if (txt_sotien.Text != "")
            {
                txt_sotien.Text = txt_sotien.Text.Substring(0, txt_sotien.Text.Length - 1);
            }
        }

        private void bton_xoa_Click(object sender, EventArgs e)
        {
            txt_sotien.Text = "";
        }

        private void bton_1chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_1chi.Text;
        }

        private void bton_2chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_2chi.Text;
        }

        private void bton_3chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_3chi.Text;
        }

        private void bton_4chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_4chi.Text;
        }

        private void bton_5chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_5chi.Text;
        }

        private void bton_6chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_6chi.Text;
        }

        private void bton_7chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_7chi.Text;
        }

        private void bton_8chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_8chi.Text;
        }

        private void bton_9chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_9chi.Text;
        }

        private void bton_xoachonchi_Click(object sender, EventArgs e)
        {
            if (txt_sotienchi.Text != "")
            {
                txt_sotienchi.Focus();
                txt_sotienchi.Text = txt_sotienchi.Text.Substring(0, txt_sotienchi.Text.Length - 1);
            }
        }

        private void bton_0chi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text += bton_0chi.Text;
        }

        private void bton_xoachi_Click(object sender, EventArgs e)
        {
            txt_sotienchi.Focus();
            txt_sotienchi.Text = "";
        }

        #endregion

        private void bton_luuphieuthu_Click(object sender, EventArgs e)
        {
            // them mot phieu thu
            thongbao = new thongbao_lang();
            if (luoi_lydothu.DefaultView.RowCount <= 0 || txt_sotien.Text == "")
                return;
            int ketqua;
            string sotien = txt_sotien.Text;
            string malydothu = grid_lydothu.GetRowCellValue(grid_lydothu.FocusedRowHandle, col_malydothu).ToString();
            ketqua = f_insertphieuthu(malydothu, sotien, txt_makhachhang.Text);
            if (ketqua > -1)
            {
                thongbao.show_info(str_lang, "thanhcong");
                //Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "Thêm phiếu thu thành công", loaithongbao.canhbao.GetHashCode());
                m_makhachhang = "";
             
            }

            // hien thi danh sach phieu thu len luoi
            grdPhieuThu.MainView = grvPhieuThu;
            grdPhieuThu.DataSource = null;
            grdPhieuThu.DataSource = f_selectdsphieuthu(7);
        }

        //------------------------------------------------------------------------------------------------------------
        private void bton_luuphieuchi_Click(object sender, EventArgs e)
        {
            // them mot phieu chi
            thongbao = new thongbao_lang();
            if (luoi_lydochi.DefaultView.RowCount <= 0 || txt_sotienchi.Text == "")
                return;
            int ketqua;
            string sotien = txt_sotienchi.Text;
            string malydochi = grid_lydochi.GetRowCellValue(grid_lydochi.FocusedRowHandle, col_malydochi).ToString();
            ketqua = f_insertphieuchi(malydochi, sotien);
            if (ketqua == 2)
            {
                thongbao.show_info(str_lang, "khongthanhcong");
                //Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "Thêm phiếu chi không thành công", loaithongbao.canhbao.GetHashCode());
                return;
            }

            // hien thi danh sach phieu thu len luoi
            grdPhieuChi.MainView = grvPhieuChi;
            grdPhieuChi.DataSource = null;
            grdPhieuChi.DataSource = f_selectdsphieuchi(8);
        }


        private void grid_dsphieuthu_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            if (grdPhieuThu.DefaultView.RowCount > 0)
            {
                GridView grid = (GridView)sender;

                int chiso = e.FocusedRowHandle;
                string _chiso = Convert.ToString(chiso);
                GridColumn col = grvPhieuThu.FocusedColumn;
                txt_sotien.Text = grvPhieuThu.GetRowCellDisplayText(chiso, col_sotien) + "";
                if (check_MAKHACHHANG.Checked)
                {
                    txt_khachhang.Text = grvPhieuThu.GetRowCellDisplayText(chiso, col_khachhang) + "";
                    txt_makhachhang.Text = grvPhieuThu.GetRowCellDisplayText(chiso, col_makhachhang) + "";
                }
                else
                {
                    txt_khachhang.Text = "";
                    txt_makhachhang.Text =  "";
                }
                
                txt_lydothu.Enabled = false;
                bton_lydo.Enabled = false;
                bton_luulydothu.Enabled = false;
            }
        }
        //----------------------------------------------------------------------------------------

        private void grid_dsphieuchi_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            if (grdPhieuChi.DefaultView.RowCount > 0)
            {
                DataRow dr = grvPhieuChi.GetDataRow(grvPhieuChi.FocusedRowHandle);


                txt_sotienchi.Text = dr["TONGTIEN"] + "";
                txt_tenNCC.Text = dr["tenNCC"] + "";
                txt_maNCC.Text = dr["maNCC"] + "";

                txt_lydochi.Enabled = false;
                bton_lydochi.Enabled = false;
                bton_luulydochi.Enabled = false;
            }
        }

        private void bton_xoaphieuthu_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            if (new cpublic().KiemTra_CoQuyen(this.Name, bton_xoaphieuthu.Name, 1))
            {
                int ketqua;
                if (grdPhieuThu.DefaultView.RowCount <= 0)    // neu khong co dong nao thi khong xoa duoc
                    return;
                string maphieuthu = grvPhieuThu.GetRowCellValue(grvPhieuThu.FocusedRowHandle, col_maphieuthu).ToString();
                thongbao.show_info(str_lang, "chatchan");
                //Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "Bạn muốn xóa?", loaithongbao.yesno.GetHashCode());
                if (Variable.thongbao == true)
                {
                    ketqua = f_deletephieuthu(maphieuthu);
                    if (ketqua > -1)
                    {
                        thongbao.show_info(str_lang, "thanhcong");
                        // mess.messagebox_pos("Thông báo", "Xóa thành công", loaithongbao.canhbao.GetHashCode());
                    }
                    // xoa mot dong trong luoi ly do thu
                    int chiso;
                    chiso = ((ColumnView)grdPhieuThu.Views[0]).FocusedRowHandle;
                    // chiso = grid_dsphieuchi.FocusedRowHandle;
                    DataView tam = (DataView)grdPhieuThu.Views[0].DataSource;
                    tam.Delete(chiso);
                    if (grvPhieuThu.RowCount <= 0)
                    {
                        txt_khachhang.Text = "";
                        txt_sotien.Text = "";
                    }
                }
            }
            else
            {
                thongbao.show_info(str_lang, "quyen");
                //MessageBox_LPV.Show("Bạn không có quyền");
            }
        }

        //---------------------------------------------------------------------------------------------------

        private void bton_xoaphieuchi_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            if (new cpublic().KiemTra_CoQuyen(this.Name, bton_xoaphieuchi.Name, 1))
            {
                thongbao = new thongbao_lang();
                int ketqua;
                if (grdPhieuChi.DefaultView.RowCount <= 0)    // neu khong co dong nao thi khong xoa duoc
                    return;
                string maphieuchi = grvPhieuChi.GetRowCellValue(grvPhieuChi.FocusedRowHandle, col_maphieuchi).ToString();
                thongbao.show_info(str_lang, "chatchan");
                //Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "Bạn muốn xóa?", loaithongbao.yesno.GetHashCode());
                if (Variable.thongbao == true)
                {
                    ketqua = f_deletephieuchi(maphieuchi);
                    if (ketqua >= 1)
                    {
                        thongbao.show_info(str_lang, "thanhcong");
                        //Mod_messagebox mess = new Mod_messagebox();
                        //mess.messagebox_pos("Thông báo", "Xóa thành công", loaithongbao.canhbao.GetHashCode());

                    }
                    // xoa mot dong trong luoi ly do thu
                    int chiso;
                    chiso = ((ColumnView)grdPhieuChi.Views[0]).FocusedRowHandle;
                    DataView tam = (DataView)grdPhieuChi.Views[0].DataSource;
                    tam.Delete(chiso);
                    if (grvPhieuChi.RowCount <= 0)
                    {
                        txt_sotienchi.Text = "";
                    }
                }
            }
            else
            {
                thongbao.show_info(str_lang, "quyen");
                    //MessageBox_LPV.Show("Bạn không có quyền");
            }
                
        }

        private void bton_suaphieuthu_Click(object sender, EventArgs e)
        {
            if (new cpublic().KiemTra_CoQuyen(this.Name, bton_suaphieuthu.Name, 1))
            {
                thongbao = new thongbao_lang();
                int chiso = -1;
                int ketqua;
                if (grvPhieuThu.RowCount <= 0)
                    return;
                string maphieuthu = grvPhieuThu.GetRowCellValue(grvPhieuThu.FocusedRowHandle, col_maphieuthu).ToString();
                string tongtien = txt_sotien.Text;
                Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "Bạn muốn lưu?", loaithongbao.yesno.GetHashCode());
                //if (Variable.thongbao == true)
                //{
                ketqua = f_updatephieuthu(maphieuthu, tongtien, txt_makhachhang.Text);
                if (ketqua != -1)
                {
                    thongbao.show_info(str_lang, "thanhcong");
                    //Mod_messagebox mess = new Mod_messagebox();
                    //mess.messagebox_pos("Thông báo", "Lưu thành công", loaithongbao.canhbao.GetHashCode());

                }
                else
                {
                    thongbao.show_info(str_lang, "khongthanhcong");
                    //mess.messagebox_pos("Thông báo", "Lưu không thành công", loaithongbao.canhbao.GetHashCode());
                    return;
                }


                chiso = ((ColumnView)grdPhieuThu.Views[0]).FocusedRowHandle;
                //luoi_dsphieuthu.DataSource = null;
                //luoi_dsphieuthu.DataSource = f_selectdsphieuthu(2);
                grvPhieuThu.SetFocusedRowCellValue(col_sotien, tongtien);

                //if ( chiso != -1)
                //{
                //    grid_dsphieuthu.SelectRow(chiso);
                //    grid_dsphieuthu.FocusedRowHandle = chiso;
                //}
                //}
            }
            else
            {
                thongbao.show_info(str_lang, "quyen");
                //MessageBox_LPV.Show("Bạn không có quyền");
            }
               
        }

        //------------------------------------------------------------------------------------------------------------

        private void bton_suaphieuchi_Click(object sender, EventArgs e)
        {
            if (new cpublic().KiemTra_CoQuyen(this.Name, bton_suaphieuchi.Name, 1))
            {
                thongbao = new thongbao_lang();
                
                int chiso = -1;
                int ketqua;
                
                if (grid_lydochi.RowCount <= 0)
                    return;

                string maphieuchi = grvPhieuChi.GetRowCellValue(grvPhieuChi.FocusedRowHandle, col_maphieuchi).ToString();
                string tongtien = txt_sotienchi.Text;
                Mod_messagebox mess = new Mod_messagebox();
                
                ketqua = f_updatephieuchi(maphieuchi, tongtien);
                if (ketqua != -1)
                {
                    thongbao.show_info(str_lang, "thanhcong");
                    mess.messagebox_pos("Thông báo", "Lưu thành công", loaithongbao.canhbao.GetHashCode());
                }
                else
                {
                    thongbao.show_info(str_lang, "khongthanhcong");                    
                    return;
                }
                chiso = ((ColumnView)grdPhieuChi.Views[0]).FocusedRowHandle;
                                
                grdPhieuChi.DataSource = f_selectdsphieuchi(8);
                //grvPhieuChi.SetFocusedRowCellValue(col_sotienchi, tongtien);
            }
            else
            {
                thongbao.show_info(str_lang, "quyen");                
            }
                
        }

        private void bton_lydochi_Click(object sender, EventArgs e)
        {
            txt_lydochi.Text = new cpublic().loadformchu_point(350,250);
        }

        private void bton_hienhanhphieuthu_Click(object sender, EventArgs e)
        {
          
            int ketqua = -1;
            string lydothu = "";
            string ngay = "";
            string sotien = "";
            if (grvPhieuThu.RowCount > 0)
            {
                lydothu = grvPhieuThu.GetRowCellValue(grvPhieuThu.FocusedRowHandle, col_tenlydothu).ToString();
                ngay =  ((DateTime)grvPhieuThu.GetRowCellValue(grvPhieuThu.FocusedRowHandle, col_ngay)).ToString("dd/MM/yyyy") + "   ";
                sotien = decimal.Parse( grvPhieuThu.GetRowCellValue(grvPhieuThu.FocusedRowHandle, col_sotien) + "").ToString("N0");
                ketqua = f_inphieuthu_chihienhanh("Báo cáo phiếu thu", lydothu, ngay, sotien, true);
            }
            else
            {
                Mod_messagebox mess = new Mod_messagebox();
                mess.messagebox_pos("Thông báo", "Chưa có dữ liệu", loaithongbao.thongtin.GetHashCode());
                return;
            }
            if (ketqua == -1)
            {
                Mod_messagebox mess = new Mod_messagebox();
                mess.messagebox_pos("Thông báo", "In không thành công", loaithongbao.thongtin.GetHashCode());
                return;
            }

        }

        private void bton_intatcaphieuthu_Click(object sender, EventArgs e)
        {
            if (grvPhieuThu.RowCount < 0)
            {
                Mod_messagebox mess = new Mod_messagebox();
                mess.messagebox_pos("Thông báo", "Chưa có dữ liệu", loaithongbao.thongtin.GetHashCode());
                return;
            }
            if (grvPhieuThu.RowCount <= 0)
            {
                Mod_messagebox mess = new Mod_messagebox();
                mess.messagebox_pos("Thông báo", "Chưa có dữ liệu", loaithongbao.thongtin.GetHashCode());
                return;
            }
            f_intatcaphieuthu();
        }

        private void bton_hienhanhphieuchi_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            int ketqua = -1;
            string lydothu = "";
            string ngay = "";
            string sotien = "";
            if (grvPhieuChi.RowCount > 0)
            {
                lydothu = grvPhieuChi.GetRowCellValue(grvPhieuChi.FocusedRowHandle, col_lydochi).ToString();
                ngay = ((DateTime) grvPhieuChi.GetRowCellValue(grvPhieuChi.FocusedRowHandle, col_ngaychi)).ToString("dd/MM/yyyy")+ "   ";
                sotien = decimal.Parse(grvPhieuChi.GetRowCellValue(grvPhieuChi.FocusedRowHandle, col_sotienchi) + "").ToString("N0");
                ketqua = f_inphieuthu_chihienhanh("Báo cáo phiếu chi", lydothu, ngay, sotien, false);
            }
            else
            {
                thongbao.show_info(str_lang, "dulieu");
                //Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "Chưa có dữ liệu", loaithongbao.thongtin.GetHashCode());
                return;
            }
            if (ketqua == -1)
            {
                thongbao.show_info(str_lang, "khongthanhcong");
                //Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "In không thành công", loaithongbao.thongtin.GetHashCode());
                return;
            }

        }

        private void bton_intatcaphieuchi_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
                 
            if (grvPhieuChi.RowCount < 0)
            {
                thongbao.show_info(str_lang, "dulieu");
                //Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "Chưa có dữ liệu", loaithongbao.thongtin.GetHashCode());
                return;
            }
            if (grvPhieuChi.RowCount <= 0)
            {
                thongbao.show_info(str_lang, "dulieu");
                //Mod_messagebox mess = new Mod_messagebox();
                //mess.messagebox_pos("Thông báo", "Chưa có dữ liệu", loaithongbao.thongtin.GetHashCode());
                return;
            }
            f_intatcaphieuchi();
            
        }

        private void bton_timthu_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            frm_tungaydenngay = new mh_tungaydenngay();
            frm_tungaydenngay.ShowDialog();

            if (frm_tungaydenngay.DialogResult == DialogResult.OK)
            {
                if (int.Parse(frm_tungaydenngay.str_fromdate) > int.Parse(frm_tungaydenngay.str_todate))
                {
                    thongbao.show_info(str_lang, "tungaynhohon");
                    //Mod_messagebox mess = new Mod_messagebox();
                    //mess.messagebox_pos("Thông báo", "Từ ngày phải nhỏ hơn đến ngày", loaithongbao.thongtin.GetHashCode());
                    return;
                }
                grdPhieuThu.MainView = grvPhieuThu;
                grdPhieuThu.DataSource = f_luoilydothutheothoigian(frm_tungaydenngay.str_fromdate, frm_tungaydenngay.str_todate);
                return;
            }
            
        }

        private void bton_timchi_Click(object sender, EventArgs e)
        {
            thongbao = new thongbao_lang();
            frm_tungaydenngay = new mh_tungaydenngay();
            frm_tungaydenngay.ShowDialog();
            if (frm_tungaydenngay.DialogResult == DialogResult.OK)
            {
                if (int.Parse(frm_tungaydenngay.str_fromdate) > int.Parse( frm_tungaydenngay.str_todate))
                {
                    thongbao.show_info(str_lang, "tungaynhohon");
                    //Mod_messagebox mess = new Mod_messagebox();
                    //mess.messagebox_pos("Thông báo", "Từ ngày phải nhỏ hơn đến ngày", loaithongbao.thongtin.GetHashCode());
                    return;
                }
                grdPhieuChi.MainView = grvPhieuChi;
                grdPhieuChi.DataSource = f_luoilydochitheothoigian(frm_tungaydenngay.str_fromdate, frm_tungaydenngay.str_todate);
                return;
            }
        }

        private void luoi_dsphieuthu_Click(object sender, EventArgs e)
        {

        }

        private void grid_dsphieuthu_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            GridView view = (GridView)sender;
            //Check whether the indicator cell belongs to a data row
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                int stt = 1 + e.RowHandle;
                e.Info.DisplayText = stt.ToString();
            }
        }

        private void grid_dsphieuchi_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            GridView view = (GridView)sender;
            //Check whether the indicator cell belongs to a data row
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                int stt = 1 + e.RowHandle;
                e.Info.DisplayText = stt.ToString();

            }
        }

        private void bton_xemtatca_thu_Click(object sender, EventArgs e)
        {
             // hien thi ds phieu thu
            grdPhieuThu.MainView = grvPhieuThu;
            grdPhieuThu.DataSource = null;
            grdPhieuThu.DataSource = f_selectdsphieuthu(2);
        }

        private void bton_xemtatca_chi_Click(object sender, EventArgs e)
        {
            // hien thi ds phieu chi
            grdPhieuChi.MainView = grvPhieuChi;
            grdPhieuChi.DataSource = f_selectdsphieuchi(4);


        }

        private void panelControl10_Paint(object sender, PaintEventArgs e)
        {

        }

        private void bton_chonkh_Click(object sender, EventArgs e)
        {
            mh_select_khachhang frm_selectkhachhang = new mh_select_khachhang();   
            frm_selectkhachhang.ShowDialog();
            if (frm_selectkhachhang.DialogResult == DialogResult.OK)
            {
                m_makhachhang = frm_selectkhachhang.m_makhachhang;
                txt_khachhang.Text = frm_selectkhachhang.m_tenkhachhang;
                txt_makhachhang.Text = frm_selectkhachhang.m_makhachhang;
            }
            
        }

        private void check_khachhang_CheckedChanged(object sender, EventArgs e)
        {
            if (check_MAKHACHHANG.Checked)
            {
                txt_makhachhang.Text = grvPhieuThu.GetRowCellDisplayText(grvPhieuThu.FocusedRowHandle, col_makhachhang) + "";
                txt_khachhang.Text = grvPhieuThu.GetRowCellDisplayText(grvPhieuThu.FocusedRowHandle, col_khachhang) + "";
                bton_chonkh.Enabled = true;
            }
            else
            {
                txt_makhachhang.Text = "";
                txt_khachhang.Text = "";
                bton_chonkh.Enabled = false;
            }
        }

        private void bton_congnobandau_Click(object sender, EventArgs e)
        {
            mh_congnobandauphaithu frm_congnobandauphaithu = new mh_congnobandauphaithu();
            frm_congnobandauphaithu.ShowDialog();

        }

        private void bton_chonkh_chi_Click(object sender, EventArgs e)
        {
            #region "   "
            //mh_select_khachhang frm_selectkhachhang = new mh_select_khachhang();
            //frm_selectkhachhang.ShowDialog();
            //if (frm_selectkhachhang.DialogResult == DialogResult.OK)
            //{
            //    m_makhachhang = frm_selectkhachhang.m_makhachhang;
            //    txt_tenkh_chi.Text = frm_selectkhachhang.m_tenkhachhang;
            //    txt_makh_chi.Text = frm_selectkhachhang.m_makhachhang;
            //}
            #endregion

            frmDM_NHACC frm = new frmDM_NHACC(true);
            DataRow drNCC = frm.ShowForm();
            if (frm.DialogResult == DialogResult.OK && drNCC != null)
            {
                txt_maNCC.Text = drNCC["OBJID"] + "";
                txt_tenNCC.Text = drNCC["OBJNAME"] + "";
            }

        }

        private void check_kh_chi_CheckedChanged(object sender, EventArgs e)
        {
            if (check_MANCC.Checked)
            {
                txt_maNCC.Text = grvPhieuThu.GetRowCellDisplayText(grvPhieuThu.FocusedRowHandle, col_makhachhang) + "";
                txt_tenNCC.Text = grvPhieuThu.GetRowCellDisplayText(grvPhieuThu.FocusedRowHandle, col_khachhang) + "";
                bton_chonNCC.Enabled = true;
            }
            else
            {
                txt_maNCC.Text = "";
                txt_tenNCC.Text = "";
                bton_chonNCC.Enabled = false;
            }
        }

        private void grid_dsphieuchi_Click(object sender, EventArgs e)
        {
            this.grid_dsphieuchi_FocusedRowChanged(null, null);
        }

        //private void grid_dsphieuthu_FocusedRowChanged(object sender, EventArgs e)
        //{
        //    this.grid_dsphieuthu_FocusedRowChanged(null, null);
        //}
    }
}